package com.sebiotec.ambassador.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProviders;

import com.sebiotec.ambassador.R;
import com.sebiotec.ambassador.R2;
import com.sebiotec.ambassador.model.post.PostPwd;
import com.sebiotec.ambassador.viewmodel.BasicViewModel;
import com.sebiotec.ambassador.viewmodel.UpdatePwdViewModel;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.CheckPwd;

import com.sebiotec.basecommon.utils.tools.ToastTool;
import com.xw.repo.XEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class UpdatePwdActivity extends BaseActivity {


    @BindView(R2.id.qk_back)
    ImageView qkBack;
    @BindView(R2.id.tv_save)
    TextView tvSave;
    @BindView(R2.id.et_old)
    XEditText etOld;
    @BindView(R2.id.et_new)
    XEditText etNew;
    @BindView(R2.id.et_renew)
    XEditText etRenew;
    private UpdatePwdViewModel mUpdatePwdViewModel;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_update_pwd;
    }

    @Override
    protected void initUI() {
        mUpdatePwdViewModel= ViewModelProviders.of(this).get(UpdatePwdViewModel.class);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {

    }

// else if (!CheckPwd.checkPasswordRule(edPwd.getTextEx().toString().trim())){
//              XToast.error(LoginActivity.this,this.getString(R.string.yz_login_pwd)).show();
//          }

    @OnClick({R2.id.qk_back, R2.id.tv_save})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.qk_back) {
            ActivityTool.getInstance().popOneActivity(this);
        } else if (id == R.id.tv_save) {
            if (TextUtils.isEmpty(etOld.getText().toString().trim())||TextUtils.isEmpty(etNew.getText().toString().trim())||TextUtils.isEmpty(etRenew.getText().toString().trim())){

                ToastTool.showError(this,getString(R.string.pwd_is_not_null));


            }else if (!etNew.getText().toString().trim().equals(etRenew.getText().toString().trim())){

                ToastTool.showError(this,getString(R.string.pwd_is_not_same));

            }else if (!CheckPwd.checkPasswordRule(etNew.getTextEx().toString().trim())){
                ToastTool.showError(this,getString(R.string.yz_login_pwd));

            }else{
                PostPwd postPwd =new PostPwd(etOld.getText().toString().trim(),etNew.getText().toString().trim(),etRenew.getText().toString().trim());

                mUpdatePwdViewModel.save(postPwd, new BasicViewModel.MyBasicDataCallBack<Object>() {
                    @Override
                    public void onDataSuccessCallBack(Object o) {
                        ToastTool.showSuccess(UpdatePwdActivity.this,getString(R.string.update_pwd_success));

                        ActivityTool.getInstance().popOneActivity(UpdatePwdActivity.this);

                    }

                    @Override
                    public void onDataFailCallBack(Object o) {
                        ToastTool.showError(UpdatePwdActivity.this,getString(R.string.update_pwd_fail));



                    }
                });
            }


        }
    }
}
